package main

import (
	"context"
	"log"
	"myprotobuf/build/gen/myprotobuf/grpctest"
	"net"

	"google.golang.org/grpc"
)

type HelloService struct {
}

func main() {
	lis, err := net.Listen("tcp", ":8888")
	if err != nil {
		log.Fatalf("fail to listen: %v", err)
	}
	s := grpc.NewServer()
	// 注册服务
	grpctest.RegisterGreeterServer(s, &HelloService{})

	// 服务启动
	if err := s.Serve(lis); err != nil {
		log.Fatalf("fail to serve: %v", err)
	}
}

func (s *HelloService) SayHello(ctx context.Context, in *grpctest.HelloRequest) (*grpctest.HelloReply, error) {
	log.Printf("receive a request: %s", in.GetName())
	return &grpctest.HelloReply{Message: "haha"}, nil
}

func (s *HelloService) SayHelloAgain(ctx context.Context, in *grpctest.HelloRequest) (*grpctest.HelloReply, error) {
	return &grpctest.HelloReply{Message: "heihei"}, nil
}
